import React, { Component } from 'react';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import { message } from "antd";
import styles from './GetCard.css'

import IDCard from '../../components/Common/IDCard/IDCard';
import MainLayout from '../../components/MainLayout/MainLayout'

class GetCard extends Component {
    constructor(props) {
        super(props);
        this.state = {}
    }

    componentWillMount() {
        console.log('进去调用')
        this._getInfo();
    }

    componentDidMount() {
        global.clock();
        this.props.dispatch({
            type: 'clock/change',
            payload: {
                visible: true
            }
        })
    }

    _getInfo() {
        console.log('调用')
        this.props.dispatch({
            type: 'getCard/getInfo'
        })
    }

    componentWillReceiveProps(nextProps) {
        const data = nextProps.data;
        if (data.result === '0') {
            this.props.dispatch(routerRedux.push(global.ROUTER));
        } else {
            this._getInfo()
        }
    }
    
    render() {
        return (
            <MainLayout>
                <IDCard />
            </MainLayout>
        )
    }
}
const mapStateToProps = (state) => {
    const data = state.getCard.data;
    return { data };
}
export default connect(mapStateToProps)(GetCard);